package com.hackintosh.flyweight.go;

import java.awt.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @description：
 * @author：twislyn
 * @date：Created in 2021/05/15
 * @modified By：
 * @version: 1.0
 */
public class GoFactory {
    private Map<String, ChessPieces> map = new HashMap<>();

    public ChessPieces getChessPieces(String key) {
        ChessPieces chessPieces = map.get(key);
        if (chessPieces != null) {
            System.out.println("具体享元" + key + "已经存在，被成功获取！");
            return chessPieces;
        }
        switch (key) {
            case "black":
                chessPieces = new BlackPieces(key);
                map.put(key, chessPieces);
                break;
            case "white":
                chessPieces = new WhitePieces(key);
                map.put(key, chessPieces);
                break;
        }
        return chessPieces;
    }
}
